package com.taotao.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.taotao.common.resp.EasyUITreeNode;
import com.taotao.common.resp.EasyUiResult;
import com.taotao.common.resp.TaotaoResult;
import com.taotao.service.ContentCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by zzb on 2017/11/9.
 */
@Controller
@RequestMapping("/content/category")
public class ContentCategoryController {

    @Reference
    private ContentCategoryService contentCategoryService;

    //url content/category/list
    //请求的参数：id
    //响应数据：List<EasyUITreeNode>
    @RequestMapping("/list")
    @ResponseBody
    public List<EasyUITreeNode> categoryList(@RequestParam(value = "id",defaultValue = "0")long parentId) {

        List<EasyUITreeNode> contentCategoryList = contentCategoryService.getContentCategoryList(parentId);

        return contentCategoryList;
    }

    //add 节点 参数parentId:92 name:新2
    //return TaotaoResult ContentCategory对象
    @RequestMapping("/create")
    @ResponseBody
    public TaotaoResult createCategory(Long parentId,String name) {

        TaotaoResult taotaoResult = contentCategoryService.addContentCategory(parentId,name);

        return taotaoResult;
    }


}
